<?php
/*
 * Copyright 2008 by Nicholas Revels  This program is part of RMH Homebase.
 * RMH Homebase is free software.  It comes with absolutely no warranty.
 * You can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation
 * (see <http://www.gnu.org/licenses/ for more information).
*/

 include_once('RMHdate.php');
/*
 * Month is an array of dates
 * Months can start on any day
 * For any date given to the constuctor
 * the script will find the starting day and generate dates from there
 * @author Nicholas Revels
 * @version 03/17/13
 */
 
 
class Month {
	private $id;		// the first day of the month, mm-dd-yy
	private $days;		//the number of days in the month
 	private $dates;		// array of 28, 29, 30 or 31 RHMDates
	private $name;		// the name of the month (i.e. March 2008)
	private $weekday_start;	// weekday for the first day of the month
	private $timestamp;	// timestamp for the last day

 	/*
 	 * Creates a new month. A month and year are passed in
 	 * the constructor fills in the rest of the days
 	 */
 	function __construct($mm, $yy) {
 		$this->set_timestamp($mm, $yy);
 		$this->set_days(date("t", $this->get_timestamp()));
 		$this->dates[0] = new RMHdate($mm."-01-".$yy, null , "", "");
 		for($i = 1 ; $i < 8 ; $i++){
 			$this->dates[] = new RMHdate($mm."-0".($i+1)."-".$yy, null, "", "");
 		}
 		
 		for($i = 9 ; $i < $this->get_days() ; $i++){
 			$this->dates[] = new RMHdate($mm."-".($i+1)."-".$yy, null, "", "");
 		}
 		
		$this->set_name(date("F, Y", $this->get_timestamp() ));
		$this->set_weekday_start(date("W", $this->get_timestamp()));
		$this->set_id($this->dates[0]->get_id());
 	}
 	
 	//Accessor functions
 	function get_id() {
		return $this->id;
	}
	function get_days() {
		return $this->days;
	}
	function get_dates() {
		return $this->dates;
	}
	function get_name() {
		return $this->name;
	}
	function get_weekday_start() {
		return $this->weekday_start;
	}
	function get_timestamp(){
		return $this->timestamp;
	}
	
	//Mutator functions
	
	function set_id($idValue) {
		$this->id = $idValue;
	}
	function set_days($daysValue) {
		$this->days =$daysValue;
	}
	function set_dates($datesValue) {
		$this->dates = $datesValue;
	}
	function set_name($nameValue) {
		$this->name = $nameValue;
	}
	function set_weekday_start($weekdayStart) {
		$this->weekday_start = $weekdayStart;
	}
	function set_timestamp($mm, $yy){
		$this->timestamp=mktime(0,0,0,$mm,1,$yy);
	}
	
 }
 ?>
